/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.engagesoft.cashflow.bean;

import com.engagesoft.cashflow.entidades.Documento;
import com.engagesoft.cashflow.entidades.TipoDocumento;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author rchajin
 */
@Stateless
public class DocumentoFacade extends AbstractFacade<Documento> {
    @PersistenceContext(unitName = "com.engagesoft_CashFlow_war_1.0PU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public DocumentoFacade() {
        super(Documento.class);
    }
    
    public List<Documento> encontrarTodos() {
        List<Documento> doc = new ArrayList<>();
        
        try {
            Query q = em.createNamedQuery("Documento.findAll");
            doc = (List<Documento>) q.getResultList();
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        return doc;
    }  
    
    public List<Documento> encontrarPorTipoDocumento(int tipo) {
        List<Documento> doc = new ArrayList<>();
        
        TipoDocumento td = new TipoDocumento();
        td.setIdTipoDocumento(tipo);
        
        try {
            Query q = em.createNamedQuery("Documento.findByTipoDocumento").setParameter("idTipoDocumento", td);
            doc = (List<Documento>) q.getResultList();
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        return doc;
    }    
}
